<body class="iframe">
    <div class="task">
        <div class="frame-header">
            <h2><i class="layui-icon">&#xe705;</i>设置</h2>
        </div>
        <h4 class="layui-bg-dark frame-title"><i class="layui-icon">&#xe65f;</i>配置管理</h4>
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
                <li class="layui-this">邮件配置</li>
                <?php if ($userinfo['level'] == 99): ?>
                    <li>网站配置</li>
                <?php endif; ?>
                <li>发送配置</li>

            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form" action="">
                        <?php foreach ($webconfig as $rows): ?>
                            <div class="layui-form-item">
                                <label class="layui-form-label"><?= $rows['title'] ?></label>
                                <div class="layui-input-inline">
                                    <input type="text" name="<?= $rows['name'] ?>" required lay-verify="required" placeholder="请填写配置项" <?php if ($userinfo['level'] != 99): ?>disabled<?php endif; ?> value="<?= $rows['value'] ?>" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux"><?= $rows['brief'] ?></div>
                            </div>

                        <?php endforeach; ?>

                        <?php if ($userinfo['level'] == 99): ?>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn send-btn" lay-submit lay-filter="updateconfig">修改</button>
                                </div>
                            </div>
                        <?php endif; ?>

                    </form>

                </div>
                <?php if ($userinfo['level'] == 99): ?>
                    <div class="layui-tab-item">
                        <form class="layui-form" action="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">部门名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="department" required lay-verify="required" placeholder="请填写名称"  autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn send-btn" lay-submit lay-filter="adddepartment">添加</button>
                                </div>
                            </div>
                        </form>
                        <div class="data-table">
                            <table class="layui-table">
                                <thead>
                                    <tr>
                                        <th>序号</th>
                                        <th>部门id</th>
                                        <th>部门</th>
                                        <th>添加时间</th>
                                    </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                        </div>

                    </div>
                <?php endif; ?>
                <div class="layui-tab-item">
                    <form class="layui-form" action="">
                        <?php foreach ($sendconfig as $rows): ?>
                            <div class="layui-form-item">
                                <label class="layui-form-label"><?= $rows['department_name'] ?></label>
                                <div class="layui-input-inline">
                                    <input type="text" name="sendname" required lay-verify="required" placeholder="请填写自定义发件昵称"  value="<?= $rows['send_name'] ?>" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">发件昵称</div>
                            </div>
                        <?php endforeach; ?>
                        <?php if ($userinfo['level'] == 50): ?>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn send-btn" lay-submit lay-filter="updatesendname">修改</button>
                                </div>
                            </div>
                        <?php endif; ?>

                    </form>

                </div>
            </div>
        </div>

    </div>
</body>
<script>
    layui.use(['element', 'form', 'layer'], function () {
        var element = layui.element, form = layui.form, layer = layui.layer;
<?php if ($userinfo['level'] == 99): ?>
            getDepartmentList();
<?php endif; ?>
        form.on('submit(updatesendname)', function (data) {
            let url = '<?= site_url("home/update_sendname") ?>';
            let jsonData = {
                'sendname': data.field.sendname,
            };
            noCallbackRequest(url, jsonData, layer);
            return false;
        })

        form.on('submit(updateconfig)', function (data) {
            let url = '<?= site_url("home/update_config") ?>';
            let jsonData = {
                'config': data.field,
            };
            noCallbackRequest(url, jsonData, layer);
            return false;
        })

        form.on('submit(adddepartment)', function (data) {
            let url = '<?= site_url("home/add_department") ?>';
            let department = data.field.department;
            let jsonData = {
                'department': department
            };
            request(url, jsonData, getDepartmentList, layer);
            return false;
        })

    });
    function getDepartmentList() {
        let url = '<?= site_url("home/get_department") ?>';
        $.get(url, function (redata) {
            let str = '';
            if (redata.errno == '666') {
                for (x in redata.departmentlist) {
                    let num = parseInt(x) + 1;
                    str += '<tr tid="' + redata.departmentlist[x].id + '"><td>' + num + '</td><td>' + redata.departmentlist[x].id + '</td><td>' + redata.departmentlist[x].department_name + '</td><td>' + redata.departmentlist[x].create_time + '</td></tr>';
                }
                $('.data-table tbody').html(str);
            } else {
                layer.msg(redata.error);
                $('.data-table tbody').html(str);
            }
        }, 'json');

    }

</script>

</html>